<?php

namespace App\Modules\Admin\Http\Controllers;

use App\Http\Controllers\BaseController;
use App\Services\CulturalHeritageTypeService;
use Illuminate\Http\Request;

class CulturalHeritageTypeController extends BaseController
{
    public function __construct(CulturalHeritageTypeService $culturalHeritageTypeService)
    {
        $this->middleware('check.adminLogin')->except('index');

        $this->culturalHeritageTypeService = $culturalHeritageTypeService;
    }

    public function index()
    {
        $param = [];
        $data = $this->culturalHeritageTypeService->getAll($param);

        return $this->response->success($data);
    }

    public function show(Request $request)
    {
        $id = $request->input('id');
        $result = $this->culturalHeritageTypeService->getInfo($id);

        return $this->response->success($result);
    }

    public function store(Request $request)
    {
        $param = $this->validationParameter([
            'name|非遗名称' => 'require',
            'cover|图片' => 'require',
        ]);

        $param['publisher_uid'] = $request->user()->admin_uid ?? null;

        $result = $this->culturalHeritageTypeService->add($param);

        return $this->response->success($result);
    }

    public function update(Request $request)
    {
        $id = $request->input('id');
        $param = [];
        $result = $this->culturalHeritageTypeService->update($param, $id);

        return $this->response->success($result);
    }

    public function destroy(Request $request)
    {
        $id = $request->input('id');
        $result = $this->culturalHeritageTypeService->delete($id);

        return $this->response->success($result);
    }
}
